package com.zjxf.service.impl;

import com.zjxf.base.bean.po.UmsStore;
import com.zjxf.base.common.OperationException;
import com.zjxf.service.AppService;
import com.zjxf.service.UmsStoreService;
import com.zjxf.utils.AddressUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * created with IntelliJ IDEA
 *
 * @author: create by limu
 * Date: 2021/4/6
 * Time：15:28
 */
@AllArgsConstructor
@Service
@Transactional(rollbackOn = RuntimeException.class)
public class AppServiceImpl implements AppService {

    public final UmsStoreService umsStoreService;

    @Override
    public Long getRegionByStr(String locationStr) throws OperationException {
        if (AddressUtils.checkLocationStr(locationStr)) {
            return umsStoreService.findAll().stream()
                    .filter(item -> locationStr.contains(item.getCounty()))
                    .findFirst().map(UmsStore::getId).orElse(0L);
        } else throw new OperationException("地址信息不合法");
    }
}
